<!-- rem单位基准声明 -->
var designWidth = 375, maxWidth = 500, bodyFontSize = 16, baseFontSize = 100
_setBaseFontSize()
_setBodyFontSize()
_setReCalcRem()

// 设置文档默认字体
function _setBodyFontSize () {
  if (document.body) document.body.style.fontSize = bodyFontSize + 'px'
  else document.addEventListener('DOMContentLoaded', _setBodyFontSize, false)
}

// 设置REM基准字号 1rem = 设计图尺寸 / 屏幕dpr / 基准字号
function _setBaseFontSize () {
  var clientWidth = document.documentElement.clientWidth
  var rem = baseFontSize * Math.min(clientWidth, maxWidth) / designWidth
  document.documentElement.style.fontSize = rem + 'px'
  window.rem = rem / 100
}

// 设置屏幕尺寸变化事件代理, 重新计算REM基准尺寸
function _setReCalcRem () {
  document.addEventListener('DOMContentLoaded', _setBaseFontSize, false)
  window.addEventListener('orientationchange' in window ? 'orientationchange' : 'resize', _setBaseFontSize, false)
}